/**
 * @file index.js
 * @author swan
 */
const app = getApp()
var goodsData = require('../../data/goods-data.js')
var util = require('../../utils/util.js')
Page({
    data: {
        'host' : getApp().getUrl()
    },
    onLoad: function () {
        swan.showToast({
            title: '正在加载...',
            icon: 'loading',
            duration: 1500
        });
        console.log(getApp().getUrl())
        swan.request({
            url: getApp().getUrl('/v1/index'),
            success: res => {
                let data = res.data.data;
                console.log(data);
                this.setData(data)
            },
            fail: err => {
                swan.showToast({
                    title: '商品展示失败',
                    icon: 'none'
                });
            }
        });
    
    },
    onPullDownRefresh(e) {
        var that = this;
        that.onLoad();    //刷新页面
        setTimeout(function () {
            swan.stopPullDownRefresh();    //停止下拉动作
        }, 1000)
    },
    onGoodsTap(event) {
        var goodsId = event.currentTarget.dataset.goodsId;
        swan.navigateTo({
            url: "../goods/goods-detail/goods-detail?id=" + goodsId
        })
    },
    onGoodsListTap(event) {
        swan.switchTab({
            url: "../goods/goods"
        })
    },
    showModalNotitle(e) {
        swan.showModal({
            content: this.data.noticeText.notice,
            showCancel: false
        });
    },

});
